﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Consultative;
using UserInfo;
using Email.Subscription;

public partial class Admin_Subscription_SubscriptionNewsEdit : Base.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            TypeBind();
            Bind();
        }

    }
    private void TypeBind()
    {
        IConsultativeType icon = new RConsultativeType();
        DataTable dt = icon.GetDataTable();
        dropType.DataSource = dt.DefaultView;
        dropType.DataTextField = "Name";
        dropType.DataValueField = "ID";
        dropType.DataBind();
        if (Request.QueryString["UserID"] != null && Request.QueryString["UserID"] != "")
        {
            int userid = int.Parse(Request.QueryString["UserID"]);
            string strWhere = "where UserID='" + userid + "'";
            SubscriptionEmail email = new SubscriptionEmail();
            DataTable dt1 = email.GetDataTable(strWhere);
            lblEmail.Text = dt1.Rows[0]["Email"].ToString();
        }

    }
    private void Bind()
    {
        if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "")
        {
            int id = int.Parse(Request.QueryString["ID"].ToString());
            SubscriptionNews news = new SubscriptionNews();
            SubscriptionNews ne = news.GetItem(id);
            dropType.SelectedValue = ne.Type;
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "")
        {
            int id = int.Parse(Request.QueryString["ID"].ToString());
            try
            {
                SubscriptionNews news = new SubscriptionNews();
                news.ID = id;
                news.Type = dropType.SelectedValue;
                news.Update(news);
                ShowMessage("订阅商业资讯成功！", "Subscription/SubscriptionNewsList.aspx");
            }
            catch (Exception ex)
            {
                ShowMessage("订阅商业资讯失败！", "Subscription/SubscriptionNewsList.aspx");
            }
        }
       
    }
}
